// Copyright (c) 2010 School of Software, Tsinghua University, Beijing (China)
// All rights reserved.
//
// This file is part of Geoxiom (http://code.google.com/p/geoxiom/); you may 
// redistribute it under the terms of the GNU Lesser General Public License.
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Author(s) : Kan-Le Shi

#ifndef GEOXIOM_GRAMMAR_ANALYZER_HPP
#define GEOXIOM_GRAMMAR_ANALYZER_HPP

#include "pattern.hpp"
#include "../utility/configuration.hpp"

namespace Geoxiom {
namespace Grammar {

typedef class Analyzer {
protected:
	std::vector<PatternPtr> patterns_;
	NodePtr root_;	

protected:
	void load_patterns() {
		std::string root = Geoxiom::Utility::Configuration::singleton().pattern_path;
		// enumerate all patterns and loaded them
		throw "not implemented";
	}

	void load_all() {
		load_patterns();
	}
	
	void reset(bool only_result) {
		if (!only_result) {
			for (std::vector<PatternPtr>::iterator i = patterns_.begin(), e = patterns_.end(); 
				i != e; i++)
				delete *i;
			patterns_.clear();
		}
		delete root_;
		root_ = NULL;
	}

public:
	void process(const Geoxiom::Lex::Stream &stream) {
		reset(true);
		// the main algorithm entry here
		throw "not implemented";
	}

public:
	const NodePtr get_result() { return root_; }

public:
	Analyzer() : patterns_(), root_(NULL) { load_all(); }
	~Analyzer() { reset(false); }

} *AnalyzerPtr, *AnalyzerArray;

}
}

#endif
